let querystring=require('querystring');
let http=require('http');
const postData = querystring.stringify({
  'code' : `

public class SortDemo  {

	public static void sort(long[] arr) {
		 int out,in;
		 for(out=arr.length;out>0;out--){
		 	for(in=1;in<out;in++){
		 		if(arr[in]<arr[in-1]){
		 			long temp=arr[in];
		 			arr[in]=arr[in-1];
		 			arr[in-1]=temp;
		 		}
		 	}
		 }
	}
}`
	  
});

const options = {
  hostname: 'localhost',
  port: 9999,
  path: '/sort',
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': Buffer.byteLength(postData)
  }
};

const req = http.request(options, (res) => {
  console.log(`状态码: ${res.statusCode}`);
  console.log(`响应头: ${JSON.stringify(res.headers)}`);
  res.setEncoding('utf8');
  res.on('data', (chunk) => {
    console.log(`响应主体: ${chunk}`);
  });
  res.on('end', () => {
    console.log('响应中已无数据。');
  });
});

req.on('error', (e) => {
  console.error(`请求遇到问题: ${e.message}`);
});

// 写入数据到请求主体
req.write(postData);
req.end();